#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
# @Time    : 2024/6/20 9:47
# @Author  : YangYong
# @File    : plugin_manager.py
# @describe: orderlines 插件管理
"""

import importlib
import inspect

from typing import List


class PluginFinder:
    def __init__(self, module_name: str, class_names: List[str]):
        self.module_name = module_name
        self.class_names = class_names
        self.plugins = dict()

    def __call__(self, ):
        for _class in self.class_names:
            module_str = f'{self.module_name}.{_class}'
            module = importlib.import_module(module_str)
            for name, sub in inspect.getmembers(module, inspect.isclass):
                if self.plugins.get(name):
                    raise ValueError(f'The same name {name} already exists')
                if sub.__base__.__name__ == 'BaseTask':
                    self.plugins[name] = sub
        return self.plugins
